using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Pages_Employee_ManageCustomers_AddCustomer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            txtContactNumber.Text = StringGenerator.GetContactNumber();
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        // reset all fields to blank
        txtFullName.Text = "";
        txtAddress.Text = "";
        txtEmail.Text = "";
        txtPhoneNumber.Text = "";
        txtFullName.Focus();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid) return;

        // prepare parameters
        string contactNumber = txtContactNumber.Text;
        string fullName = txtFullName.Text.Trim();
        string address = txtAddress.Text.Trim();
        string email = txtEmail.Text.Trim();
        string phoneNumber = txtPhoneNumber.Text.Trim();

        int affected;
        try
        {
            affected = DALCustomers.InsertCustomer(contactNumber, fullName, address, email, phoneNumber);
            if (affected > 0)
                lblMessage.Text = "Added successfully";
            else
                lblMessage.Text = "Error adding customer";
        }
        catch
        {
            lblMessage.Text = "Error adding customer";
        }
    }

    protected void btnRegenerate_Click(object sender, EventArgs e)
    {
        // regenerate a new random contact number
        txtContactNumber.Text = StringGenerator.GetContactNumber();
    }
}
